group '{{groupId}}'
version '{{artifactVersion}}'
{{^omitGradleWrapper}}

wrapper {
    gradleVersion = '8.7'
    distributionUrl = "https://services.gradle.org/distributions/gradle-$gradleVersion-all.zip"
}
{{/omitGradleWrapper}}

buildscript {
    ext.kotlin_version = '1.9.23'
    {{#jvm-ktor}}
    ext.ktor_version = '2.3.9'
    {{/jvm-ktor}}
    {{#jvm-retrofit2}}
    ext.retrofitVersion = '2.10.0'
    {{/jvm-retrofit2}}
    {{#useRxJava3}}
    ext.rxJava3Version = '3.1.8'
    {{/useRxJava3}}
    {{#jvm-vertx}}
    ext.vertx_version = "4.5.6"
    {{/jvm-vertx}}
    {{#jvm-spring}}
    {{#useSpringBoot3}}
    ext.spring_boot_version = "3.2.5"
    {{/useSpringBoot3}}
    {{^useSpringBoot3}}
    ext.spring_boot_version = "2.7.18"
    {{/useSpringBoot3}}
    {{/jvm-spring}}
    ext.spotless_version = "6.25.0"

    repositories {
        maven { url "https://repo1.maven.org/maven2" }
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        {{#kotlinx_serialization}}
        classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
        {{/kotlinx_serialization}}
        classpath "com.diffplug.spotless:spotless-plugin-gradle:$spotless_version"
    }
}

apply plugin: 'kotlin'
{{#moshiCodeGen}}
apply plugin: 'kotlin-kapt'
{{/moshiCodeGen}}
{{#parcelizeModels}}
apply plugin: 'kotlin-parcelize'
{{/parcelizeModels}}
{{#kotlinx_serialization}}
apply plugin: 'kotlinx-serialization'
{{/kotlinx_serialization}}
{{#idea}}
apply plugin: 'idea'
{{/idea}}
apply plugin: 'maven-publish'
apply plugin: 'com.diffplug.spotless'
{{^useSettingsGradle}}

repositories {
    maven { url "https://repo1.maven.org/maven2" }
}
{{/useSettingsGradle}}

// Use spotless plugin to automatically format code, remove unused import, etc
// To apply changes directly to the file, run `gradlew spotlessApply`
// Ref: https://github.com/diffplug/spotless/tree/main/plugin-gradle
spotless {
    // comment out below to run spotless as part of the `check` task
    enforceCheck false

    format 'misc', {
        // define the files (e.g. '*.gradle', '*.md') to apply `misc` to
        target '.gitignore'

        // define the steps to apply to those files
        trimTrailingWhitespace()
        indentWithSpaces() // Takes an integer argument if you don't like 4
        endWithNewline()
    }
    kotlin {
        ktfmt()
    }
}

test {
    useJUnitPlatform()
}
{{#idea}}

idea {
    module {
        sourceDirs += file('src/main/kotlin')
        testSourceDirs += file('src/test/kotlin')
    }
}
{{/idea}}
{{#jvm-spring-webclient}}{{#useSpringBoot3}}
kotlin {
    jvmToolchain {
        languageVersion.set(JavaLanguageVersion.of(17))
    }
}
{{/useSpringBoot3}}{{/jvm-spring-webclient}}
{{#jvm-spring-restclient}}
kotlin {
    jvmToolchain {
        languageVersion.set(JavaLanguageVersion.of(17))
    }
}
{{/jvm-spring-restclient}}
dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
    {{^doNotUseRxAndCoroutines}}
    {{#useCoroutines}}
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.0"
    {{/useCoroutines}}
    {{/doNotUseRxAndCoroutines}}
    {{#moshi}}
    {{^moshiCodeGen}}
    implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
    implementation "com.squareup.moshi:moshi-kotlin:1.15.1"
    implementation "com.squareup.moshi:moshi-adapters:1.15.1"
    {{/moshiCodeGen}}
    {{#moshiCodeGen}}
    implementation "com.squareup.moshi:moshi:1.15.1"
    implementation "com.squareup.moshi:moshi-adapters:1.15.1"
    kapt "com.squareup.moshi:moshi-kotlin-codegen:1.15.1"
    {{/moshiCodeGen}}
    {{/moshi}}
    {{#gson}}
    implementation "com.google.code.gson:gson:2.10.1"
    {{/gson}}
    {{#jackson}}
    implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
    implementation "com.fasterxml.jackson.module:jackson-module-kotlin:2.17.1"
    implementation "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.17.1"
    {{/jackson}}
    {{#kotlinx_serialization}}
    implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.3"
    {{/kotlinx_serialization}}
    {{#jvm-ktor}}
    implementation "io.ktor:ktor-client-core:$ktor_version"
    implementation "io.ktor:ktor-client-content-negotiation:$ktor_version"
    {{#gson}}
    implementation "io.ktor:ktor-serialization-gson:$ktor_version"
    implementation "io.ktor:ktor-client-gson:$ktor_version"
    {{/gson}}
    {{#jackson}}
    implementation "io.ktor:ktor-client-jackson:$ktor_version"
    implementation "io.ktor:ktor-serialization-jackson:$ktor_version"
    {{/jackson}}
    {{/jvm-ktor}}
    {{#jvm-okhttp4}}
    implementation "com.squareup.okhttp3:okhttp:4.12.0"
    {{/jvm-okhttp4}}
    {{#jvm-spring-webclient}}
    implementation "org.springframework.boot:spring-boot-starter-webflux:$spring_boot_version"
    implementation "io.projectreactor:reactor-core:3.6.5"
    {{/jvm-spring-webclient}}
    {{#jvm-spring-restclient}}
    implementation "org.springframework.boot:spring-boot-starter-web:$spring_boot_version"
    {{/jvm-spring-restclient}}
    {{#threetenbp}}
    implementation "org.threeten:threetenbp:1.6.8"
    {{/threetenbp}}
    {{#kotlinx-datetime}}
    implementation "org.jetbrains.kotlinx:kotlinx-datetime:0.5.0"
    {{/kotlinx-datetime}}
    {{#jvm-retrofit2}}
    {{#hasOAuthMethods}}
    implementation "org.apache.oltu.oauth2:org.apache.oltu.oauth2.client:1.0.2"
    {{/hasOAuthMethods}}
    implementation "com.squareup.okhttp3:logging-interceptor:4.12.0"
    {{#useRxJava3}}
    implementation "io.reactivex.rxjava3:rxjava:$rxJava3Version"
    implementation "com.squareup.retrofit2:adapter-rxjava3:2.10.0"
    {{/useRxJava3}}
    implementation "com.squareup.retrofit2:retrofit:$retrofitVersion"
    {{#gson}}
    implementation "com.squareup.retrofit2:converter-gson:$retrofitVersion"
    {{/gson}}
    {{#moshi}}
    implementation "com.squareup.retrofit2:converter-moshi:$retrofitVersion"
    {{/moshi}}
    {{#kotlinx_serialization}}
    implementation "com.squareup.retrofit2:converter-kotlinx-serialization:$retrofitVersion"
    {{/kotlinx_serialization}}
    {{#jackson}}
    implementation "com.squareup.retrofit2:converter-jackson:$retrofitVersion"
    {{/jackson}}
    implementation "com.squareup.retrofit2:converter-scalars:$retrofitVersion"
    {{/jvm-retrofit2}}
    testImplementation "io.kotlintest:kotlintest-runner-junit5:3.4.2"
    {{#jvm-vertx}}
    implementation "io.vertx:vertx-web-client:$vertx_version"
    implementation "io.vertx:vertx-core:$vertx_version"
    implementation "io.vertx:vertx-lang-kotlin:$vertx_version"
    implementation "io.vertx:vertx-uri-template:$vertx_version"
    {{#useCoroutines}}
    implementation "io.vertx:vertx-lang-kotlin-coroutines:$vertx_version"
    {{/useCoroutines}}
    {{/jvm-vertx}}
}
{{#kotlinx_serialization}}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
    kotlinOptions {
        freeCompilerArgs += "-Xopt-in=kotlinx.serialization.ExperimentalSerializationApi"
    }
}
{{/kotlinx_serialization}}
